/*
 * acm1365.c
 *
 *  Created on: 24 Mar 2010
 *      Author: xuxu
 */

#include<stdio.h>
#include<string.h>
int main()
{
	int total;
	char source[100],dest[100];
	int length;
	char flytype;
	total=0;
	while(scanf("%s",source))
	{
		if(0==strcmp(source,"0"))
		{
			printf("%d\n",total);
			total=0;
			continue;
		}
		if(0==strcmp(source,"#"))
			break;
		scanf("%s %d %c",dest,&length,&flytype);
		if('F'==flytype)
		{
			total+=length*2;
		}
		else if('B'==flytype)
		{
			total+=length*1.5;
		}
		else
		{
			if(length<500)
				total+=500;
			else
				total+=length;
		}
	}
	return 0;
}
